<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
    <link href="framework/reset.css" rel="stylesheet">
    <link href="css/payment.css" rel="stylesheet">
    <script src="js/payment.js"></script>
    <script src="js/pageJump.js"></script>
    <script src="https://fastly.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <title>饿了么 在线支付</title>
</head>

<body>
    <div class="wrapper" id="app">

        <!-- header部分 -->
        <header>
            <p>在线支付</p>
        </header>

        <!-- 订单信息部分 -->
        <h3>订单信息：</h3>
        <div class="order-info" >
            <p>
                {{order.restaurant.businessName}}
                
            </p>
            <p>&#165;{{order.order.orderTotal-points/100}}</p>
        </div>

        <!-- 订单明细部分 -->
        <ul class="order-detailet" id="detailetBox">
            <li v-for="food in foods">
                <p>{{food.foodName}} x {{food.quantity}}</p>
                <p>&#165;{{food.foodPrice}}</p>
            </li>
            
            <li>
                <p>配送费</p>
                <p>&#165;{{order.restaurant.deliveryPrice}}</p>
            </li>
            <li>
                <p>积分抵扣</p>
                <p>&#165;{{-points/100}}</p>
            </li>
        </ul>

        <!-- 支付方式部分 -->
        <ul class="payment-type">
            <li @click="payWay=0">
                <img src="https://gw.alipayobjects.com/zos/bmw-prod/f466695f-f426-4e79-ae69-ecdf64a03c71.svg">
                <i class="fa fa-check-circle" v-if="payWay==0"></i>
            </li>
            <li @click="payWay=1">
                <img src="https://td.cdn-go.cn/enterprise_payment/v0.0.9/logo.png">
                <i class="fa fa-check-circle" v-if="payWay==1"></i>
            </li>
        </ul>
        <div class="payment-button">
            <button @click="payOrder">确认支付</button>
        </div>

        <!-- 底部菜单部分 -->
        <ul class="footer">
            <li onclick="location.href='index.html'">
                <i class="fa fa-home"></i>
                <p>首页</p>
            </li>
            <li>
                <i class="fa fa-compass"></i>
                <p>发现</p>
            </li>
            <li onclick="location.href='orderList.html'">
                <i class="fa fa-file-text-o"></i>
                <p>订单</p>
            </li>
            <li>
                <i class="fa fa-user-o"></i>
                <p>我的</p>
            </li>
        </ul>
    </div>
    <script>
        var param=getRequest()
        var path=getRequestPath()
        var app=new Vue({
            el:"#app",
            data:{
            
                foods:[],
                order:{
                    order:{
                        orderTotal:0
                    },
                    restaurant:{
                        businessName:''
                    }
                },
                points:0,
                payWay:0
            },
            methods:{
                payOrder:function(){
                    axios.post(path+"/OrdersController/payOrder",null,{
                        params:{
                            orderId:param.orderId
                        },
                        headers:{
                            Authorization:this.getAuthorization()
                        }
                    }).then((respon)=>{
                        if(respon.data.code==200){
                            this.jumpTo("orderList.html")
                        }
                    }).catch((error)=>{
                        console.log(error)
                    })
                },
                getOrder:function(){
                    axios.post(path+"/OrdersController/getOrdersById",null,{
                        params:{
                            orderId:param.orderId
                        },
                        headers:{
                            Authorization:this.getAuthorization()
                        }
                    }).then((respon)=>{
                        if(respon.data.code==200){
                            this.order=respon.data.detail
                            this.foods=respon.data.detail.foods
                            this.points=respon.data.detail.points
                        }
                    }).catch((error)=>{
                        console.log(error)
                    })
                },
                getAuthorization:function(){
                    return window.localStorage.getItem("Auth")
                },
                jumpTo:function(u){
                    
                    window.location.href=u
                },
            },
            created(){
                this.getOrder()
            }
        })
    </script>
</body>

</html>